#ifndef	_MAC_REP_DEF_H
#define	_MAC_REP_DEF_H
//
#ifdef __cplusplus
extern "C" {
#endif
//
//---------------macro definition----------------------
//*************************************************************
//   ----Please add  your macro definitions here----
//       ------for example below-----------------
//*************************************************************
//============================== Debug ============================================
#define  DEBUG_INFOR_OUTPUT         0                   // 0: no debug information output,  1: debug information output
#define  DEBUG_FOC_OUTPUT           0                   // 0: no debug FOC output,1: debug FOC output
#define  DB_FOC_DATA_SIZE           540                 // debug FOC data buffer size
#define  DB_FOC_DATA_TYPE           15                  // debug FOC data type(0~9)
                                                        // 0:Phase Current
                                                        // 1:Electrical Angle
                                                        // 2:Clarke
                                                        // 3:Park
                                                        // 4:Speed PID
                                                        // 5:IBus PID
                                                        // 6:ID PID
                                                        // 7:IQ PID
                                                        // 8:IPark
                                                        // 9:Sector
                                                        // 10:Eα:Current Observer
                                                        // 11:Eα:Bang-Bang Controller
                                                        // 12:Eα:LPF
                                                        // 13:Eβ:Current Observer
                                                        // 14:Eβ:Bang-Bang Controller
                                                        // 15:Eβ:LPF
                                                        // 16:Definition by yourself
//==============================Motor Direction Control Mode========================
#define	 MOTOR_DIR_MODE             1                   // When motor is running,the direction can be switched or not.0: NO, 1: YES.
//==============================Motor Parameter=====================================
#define  MOTOR_POLE_PAIRS           4                   // the number of motor pole-pairs
#define  MOTOR_SPEED_MAX            3000                // the motor maximum speed,unit:1RPM
#define  MOTOR_SPEED_MIN            300                 // the motor minimum speed,unit:1RPM
#define  MOTOR_R                    796                 // the motor coil resistance,unit:1mΩ
#define  MOTOR_L                    637                 // the motor coil inductance,unit:1uH
//============IBUS Sampling Resistance and Operational Amplifier Multiples==========
#define  IBUS_SAMPLE_RES            50                  // the sampling resistance value of IBUS.unit: 1mΩ.
#define  IBUS_OPAMP                 3.3                 // the operational amplifier multiples of IBUS.
//==============================VM Divider Resistances==============================
#define  VM_R1                      8.2                 // the VM divider resistance 1,unit:1KΩ.
#define  VM_R2                      1020                // the VM divider resistance 2,unit:1KΩ.
//========================Current offset number ====================================
#define  CURR_OFFSET_NUM            16                  // the number of current offset.
//==============================PWM Frequrency and Dead Band Time===================
#define	 PWM_FREQUENCY_10K          10000               // PWM frequency,unit: 1hz
#define	 PWM_FREQUENCY_11K          11000               // PWM frequency,unit: 1hz
#define	 PWM_FREQUENCY_12K          12000               // PWM frequency,unit: 1hz
#define	 PWM_FREQUENCY_13K          13000               // PWM frequency,unit: 1hz
#define	 PWM_FREQUENCY_14K          14000               // PWM frequency,unit: 1hz
//
#define  PWM_FREQUENCY              PWM_FREQUENCY_12K   // PWM frequency,unit: 1hz
#define  PWM_DEAD_TIME              0xBC                // the dead band time
//========================Vector Circle Modulation Percent==========================
#define  MODULATION_PERCENT         90                  // Vector Circle Modulation Percent.The range is [70,100].
//========================Current minimum sampling window===================================
#define  TIME_MIN                   6000                // the current minimum sampling time,unit:1ns.
#define  TIME_DELAY_RATIO           70                  // the percentage of the current minimum sampling delay time.The rang is [50,75].
//==============================ID Current and IQ Current===========================
#define  ID_START                   (SHORT)0            // ID start current.The range is [-32768,32767].
//
#define  IQ_START                   (SHORT)3000         // IQ start current.The range is [0,32767].
#define  IQ_MIN                     (SHORT)10           // IQ minimum current.The range is [0,32767].
#define  IQ_MAX                     (SHORT)32000        // IQ maximum current.The range is [0,32767].
//============================Location,Open Loop and Closed Loop====================
#define  LOCATION_ANGLE             (SHORT)10923        // the location time.The range is [-32768,32767].
#define  LOCATION_TIME              120                 // the location time,unit:1ms
//
#define  OPENLP_ANGLE_STEP          20                  // the step angle in open loop.The range is [1,OPENLP_ANGLE_MAX].
#define  OPENLP_ANGLE_MIN           100                 // the minimum step angle in open loop.The range is [1,OPENLP_ANGLE_MAX].
#define  OPENLP_ANGLE_MAX           600                 // the maximum step angle in open loop.The range is [1,1000].
//
#define  OPENLP_CYCLE_MAX           6                   // the maximum cycle in open loop.The range is [1,OPENLP_ANGLE_MAX/OPENLP_ANGLE_STEP].
#define  OPENLP_LPFCOEFF_STEP       2                   // the low pass filter coefficient in open loop.The range is [1,150].
//
#define  OPENLP_IDREF_MODE          0                   // the ID REF mode in open loop.0: ID REF is fixed value.1:ID REF can be adjusted according to the speed.
#define  OPENLP_IDREF_SPEED_RANGE   2                   // the speed range in open loop.The range is [1,10].
#define  OPENLP_IDREF_TIME          1                   // the cycle of seting ID REF,unit:1ms.
#define  OPENLP_IDREF_STEP_INC      50                  // the increasing step of ID REF in open loop.
#define  OPENLP_IDREF_STEP_DEC      100                 // the decreasing step of ID REF in open loop.
#define  OPENLP_IDREF_MIN           0                   // the ID REF minimum.
#define  OPENLP_IDREF_MAX           10000               // the ID REF maximum.
//
#define  CLOSEDLP_ANGLE_COMP_MODE   1                   // the angle compasation mode in closed loop. 0: Uncompensated angle, 1:The Angle is compensated according to the speed range.
#define  CLOSEDLP_ANGLE_COMP        2730                // the compensation angle
//==================================SMC=============================================
#define  SMC_GAIN_K                 15000               // the SMC gain K.The range is about (0,65535] acording to different motors.
#define  SMC_ERROR_MAX              20000               // the SMC maximum error.The range is about (0,65535] acording to different motors.
//==================================Speed===========================================
#define  SPEED_ANGLE_NUM            10                  // the angle number for caculating speed
#define  SPEED_LPF_COEFF            22938               // the speed coefficient.The range is [16000,32768].
//=================================PID==============================================
#define  SPEED_IBUS_PID_MODE        1                   // 0: no Speed and IBus PID,1:Speed PID mode, 2:IBus PID mode
#define  SPEED_PID_PERIOD           20                  // when SPEED_IBUS_PID_MODE = 1,the Speed PID period, unit: 1 pwm cycle.The range is [SPEED_ANGLE_NUM,32767].
#define  SET_IBUS                   5                   // when SPEED_IBUS_PID_MODE = 2,the setting IBus value.unit:1A.

#define  SPEED_PID_KP               1000               // KP value of the speed PID
#define  SPEED_PID_KI               200                  // KI value of the speed PID
#define  SPEED_PID_OUTPUT_MAX       1500                // the output maximum of the speed PID
//
#define  IBUS_PID_KP                500                 // KP value of the IBus PID
#define  IBUS_PID_KI                10                  // KI value of the IBus PID
#define  IBUS_PID_OUTPUT_MAX        6000                // the output maximum of the IBus PID
//
#define  IQ_PID_MODE                1                   // 0: no IQ PID,1:IQ PID mode
#define  IQ_PID_KP                  500                 // KP value of the IQ PID
#define  IQ_PID_KI                  500                  // KI value of the IQ PID
#define  IQ_PID_OUTPUT_MAX          2000                // the output maximum of the IQ PID
//
#define  ID_PID_MODE                1                   // 0: no ID PID,1:ID PID mode
#define  ID_PID_KP                  500                 // KP value of the ID PID
#define  ID_PID_KI                  500                  // KI value of the ID PID
#define  ID_PID_OUTPUT_MAX          2000                // the output maximum of the ID PID
//==============================Brake Stage=========================================
#define  BS_CCR_START_DUTY          10                  // the start duty of PWM CCR.
#define  BS_SD_TIME                 600                 // slow down time,unit:1ms.
#define  BS_EB_TIME                 200                 // emergency brake time,unit:1ms.
//==============================Protect=============================================
// LRCP(Locked Rotor Current Protection)
#define  LRCP_IBUS                  1                   // Locked Rotor Current Protection current.unit:1A
#define  LRCP_IBUS_ADC              (uSHORT)((LRCP_IBUS*IBUS_SAMPLE_RES*IBUS_OPAMP*4096)/3300)  // the ADC data of Locked Rotor Current Protection current.
#define  LRCP_TIME                  50                  // the LRCP time, unit:1ms
// LRPP(Locked Rotor Phase Protection)
#define  LRPP_TIME                  150                 // the LRPP time, unit:1ms
// OCP(Over Current Protection)
#define  OCP_HW_EN                  1                   // Hardware OCP.0: disable Hardware OCP,1: enable Hardware OCP.
#define  OCP_IBUS_LEVEL             10                  // Over Current Protection current.unit: 1A
#define  OCP_IBUS_ADC_LEVEL         (uSHORT)((OCP_IBUS_LEVEL*IBUS_SAMPLE_RES*IBUS_OPAMP*4096)/3300)	// the ADC data of Over Current Protection current.
#define  OCP_TIME                   1                   // the OCP time, unit:1ms
// UVP(Under Voltage Protection)
#define  VM_MIN                     (180*1.414)         // the Under Voltage Protection,unit: 1V
#define  VM_MIN_ADC                 (uSHORT)((VM_MIN*VM_R1*4096*10)/((VM_R1+VM_R2)*33))	// the ADC data of the under voltage 
#define  UVP_TIME                   500                 // the UVP time, unit:1ms
// OVP(Over Voltage Protection)
#define  VM_MAX                     (260*1.414)         // the over voltage,unit: 1V
#define  VM_MAX_ADC                 (uSHORT)((VM_MAX*VM_R1*4096*10)/((VM_R1+VM_R2)*33))	// the ADC data of the over voltage 
#define  OVP_TIME                   250                 // the OVP time, unit:1ms
// OTP(Over Temperature Protection)
#define  OTP_R                      1                   // the OTP resistance,unit:1KΩ
#define  OTP_NTCR                   0.740               // the protection NTC resistance,unit:1KΩ
#define  OTP_REC_NTCR               1.895               // the recovery NTC resistance,unit:1KΩ
#define  OTP_ADC                    (uSHORT)((OTP_NTCR * 4096) / (OTP_R + OTP_NTCR))            // the ADC data of protection temperature 80℃
#define  OTP_TIME                   1000   				// the temperature protection time, unit:1ms
#define  OTP_REC_ADC                (uSHORT)((OTP_REC_NTCR * 4096) / (OTP_R + OTP_REC_NTCR))  // the ADC data of recovery temperature 50℃
#define  OTP_REC_TIME               5000                // the recovery temperature time, unit:1ms
// ACP(AC Protection)
#define  ACP_GPIO                   GPIO_ReadInputDataBit(GPIOB,GPIO_Pins_3) //the gpio of AC signal
#define  ACP_TIME                   2                   // the AC Protection time, unit:1ms
//==============================LED====================================================
#define  LED_TIME                   300                 // the LED time, unit:1ms
//---------------end macro definition----------------------
//
#ifdef __cplusplus
}
#endif
//
#endif	//_MAC_REP_DEF_H
